<!DOCTYPE html>
<html>
<head>
    {include file="layout:_meta_index" /}
</head>
<body>

<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-card">
            <fieldset class="table-search-fieldset">
                <legend>搜索信息</legend>
                    <div class="layui-form layui-form-item">
                        <div class="layui-inline">
                            <input type="text" name="username" placeholder="请输入登录名" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline">
                            <input type="text" name="admin_name" placeholder="请输入姓名" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline">
                            <input type="text" name="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline">
                            <select name="state">
                                <option value="">审核状态(全部)</option>
                                <option value="0">冻结</option>
                                <option value="1">启用</option>
                            </select>
                        </div>
                        <div class="layui-inline">
                            {form:select name="role" list="$roleList"  default="[''=>'用户角色(全部)']"}
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn" lay-submit lay-filter="listSearch">
                                <i class="layui-icon layui-icon-search"></i>
                            </button>
                        </div>
                    </div>
            </fieldset>

            <script type="text/html" id="listTableToolbar">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>添加</button>
                    <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del"><i class="layui-icon layui-icon-delete"></i>批量删除</button>
                </div>
            </script>

            <table id="listTable" lay-filter="listTable"></table>
            <script type="text/html" id="buttonTpl">
                {{#  if(d.state == 1){ }}
                <button class="layui-btn layui-btn-xs" lay-event="change">启用</button>
                {{#  } else { }}
                <button class="layui-btn layui-btn-primary layui-btn-xs" lay-event="change">冻结</button>
                {{#  } }}
            </script>
            <script type="text/html" id="listTableBar">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                {{#  if(d.id ==1){ }}
                <a class="layui-btn layui-btn-disabled layui-btn-xs"><i class="layui-icon layui-icon-delete"></i>删除</a>
                {{#  } else { }}
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                {{#  } }}
            </script>
        </div>
    </div>
</div>
{include file="layout:_footer" /}
<script>
    var del_url = '{:url("admin/remove")}';
    var add_url = '{:url("admin/edit")}';
    var change_url = '{:url("admin/change")}';
    layui.use(['form', 'table','common'], function(){
        var $ = layui.$
            ,common = layui.common
            ,table = layui.table;

        //数据列表
        table.render({
            elem: '#listTable',
            url : "{:url('admin/index')}",
            toolbar: '#listTableToolbar',
            cols : [[
                {type: 'checkbox'},
                {field: 'id', title: 'ID', align:"center"},
                {field: 'username', title: '登录名', align:'center'},
                {field: 'admin_name', title: '姓名', align:'center'},
                {field: 'email', title: '邮箱', align:'center'},
                {field: 'create_time', title: '加入时间', align:'center'},
                {field: 'last_login', title: '最后登录', align:'center'},
                {field: 'login_ip', title: '登录IP', align:'center'},
                {field: 'state', title: '审核状态', align:'center',templet: '#buttonTpl'},
                {title: '操作', fixed:"right",align:"center",templet:'#listTableBar'}
            ]],
            page: true, //是否显示分页
            limits:[50,100,200,300,500],//显示
            limit: 15 //每页默认显示的数量

        });

        //监听搜索
        common.enterSearch('listSearch');
        common.tableSearch('listSearch','listTable');

        //列表操作
        table.on('tool(listTable)', function(obj){
            var layEvent = obj.event, data = obj.data;
            if(layEvent === 'del'){ //删除
                common.tableDelete(del_url,data.id,'listTable');
            }else if (layEvent==='edit'){
                common.adminShow(add_url+'?id='+data.id,"编辑管理员",'500','440','addEdit','listTable');
            }else if(layEvent==='change'){
                var state = data.state==1?0:1;
                var msg =  data.state==1?'确定要冻结此账号？':'确定审核此账号？';
                common.tableStatus(change_url,{id:data.id,state:state},'listTable',msg);
            }
        });

        //列表工具栏操作
        table.on('toolbar(listTable)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'del':common.tableDelete(del_url,checkStatus.data,'listTable');break;
                case 'add':common.adminShow(add_url,"添加管理员",'500','440','addEdit','listTable');break;
            }
        });


    });
</script>
</body>
</html>

